import 'package:audioplayers/audioplayers.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:hitutor/Util/MyColor.dart';
import 'package:hitutor/Widget/MyImage.dart';

import 'MyDialog.dart';

class WordsPlayer extends StatefulWidget {
  bool? vertical;
  bool? white;
  String words;
  String? soundUrl;
  EdgeInsetsGeometry? margin;

  WordsPlayer({required this.words, this.soundUrl, this.margin,  this.vertical, this.white});

  @override
  State<StatefulWidget> createState() {
    return _WordsPlayer();
  }
}

class _WordsPlayer extends State<WordsPlayer> {
  // AudioPlayer audioPlayer = AudioPlayer();
  // PlayerState playerState = PlayerState.STOPPED;

  @override
  void initState() {
    // audioPlayer.onPlayerStateChanged.listen((event) {
    //   playerState = event;
    //   setState(() {});
    //   print('onPlayerStateChanged: $event');
    // });
    super.initState();
  }

  @override
  void deactivate() async {
    // int result = await audioPlayer.release();
    // if (result == 1) {
    //   print('release success');
    // }
    super.deactivate();
  }

  // play() async {
  //   int result = await audioPlayer.play(widget.soundUrl);
  //   if (result == 1) {
  //     print('play success');
  //   } else {
  //     print('play failed');
  //     showToast('play failed');
  //   }
  // }

  @override
  Widget build(BuildContext context) {
    String plyingPic = (widget.white ?? false) ? "sound-max-w.png" : "sound-max.png";
    String stopPic = (widget.white ?? false) ? "sound-mute-w.png" : "sound-mute.png";
    return Container(
        margin: widget.margin,
        child: Text("${widget.words}", style: TextStyle(fontSize: 18, color: MyColor.C7D, fontWeight: FontWeight.bold)),
        // child: widget.vertical ?? false
        //     ? Column(mainAxisSize: MainAxisSize.min, children: [
        //         // LocalImage(playerState == PlayerState.PLAYING ? plyingPic : stopPic, width: 36, padding: EdgeInsets.all(6), onTap: () {
        //         //   if (playerState != PlayerState.PLAYING) {
        //         //     play();
        //         //   }
        //         // }),
        //         Text("${widget.words}",
        //             style:
        //                 TextStyle(fontSize: 18, color: (widget.white ?? false) ? MyColor.White : MyColor.C7D, fontWeight: FontWeight.bold)),
        //       ])
        //     : Row(mainAxisSize: MainAxisSize.min, children: [
        //         Text("${widget.words}", style: TextStyle(fontSize: 18, color: MyColor.C7D, fontWeight: FontWeight.bold)),
        //         // LocalImage(playerState == PlayerState.PLAYING ? plyingPic : stopPic, width: 28, padding: EdgeInsets.all(6), onTap: () {
        //         //   if (playerState != PlayerState.PLAYING) {
        //         //     play();
        //         //   }
        //         // })
        //       ]),
    );
  }

}
